package com.css.apps.base.log.action;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.css.apps.base.log.model.SLogClientinfo;
import com.css.apps.base.log.service.QueryLog;
import com.css.db.query.TransactionCache;
import com.css.webbase.webwork.action.AbstractAction;
import com.opensymphony.xwork.Action;

import net.sf.json.JSONObject;

@SuppressWarnings("serial")
public class ClientInfoJbo extends AbstractAction {

	private static Log log = LogFactory.getLog(ClientInfoJbo.class);

	@Override
	public String go() {
		Calendar cal = Calendar.getInstance();
		int month = cal.get(Calendar.DAY_OF_MONTH);
		int day = cal.get(Calendar.DAY_OF_MONTH);
		if (month == 1 && day == 1) {
			// 统计去年
			statisticsYear();
			statisticsYearOfLongin();
		}
		if ((month == 1 || month == 4 || month == 7 || month == 10) && day == 1) {
			// 统计上个季度
			statisticsQuater();
			statisticsQuaterOfLogin();
		}
		if (day == 1) {
			// 统计上个月
			statisticsMonth();
			statisticsMonthOfLogin();
		}

		statisticsDay();
		statisticsDayOfLogin();

		return Action.SUCCESS;
	}

	@SuppressWarnings("unchecked")
	private String statisticsYear() {
		TransactionCache tx = null;
		Calendar cal = Calendar.getInstance();
		Date createTime = cal.getTime();
		cal.add(Calendar.YEAR, -1);
		String lastyear = new SimpleDateFormat("yyyy").format(cal.getTime());
		String sql = "select a.opExplorer , count(a.opExplorer) from SLog a where to_char(a.opTime,'yyyy') = :opTime group by a.opExplorer ";
		QueryLog qc = new QueryLog(sql);
		qc.setParameter("opTime", lastyear);

		List<Object[]> rlst = qc.list();
		JSONObject json = new JSONObject();
		if (rlst != null) {
			for (Object[] objs : rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					json.put(type, value);
				}
			}
		}
		SLogClientinfo clientinfo = new SLogClientinfo();
		clientinfo.setCountType("1");// 统计全部浏览器
		clientinfo.setLogType("4");// 按年统计
		clientinfo.setCountKey(lastyear);
		clientinfo.setContent(json.toString());
		clientinfo.setCreateTime(createTime);

		// 查询统计系统信息
		String os_sql = "select a.opOs , count(a.opOs) from SLog a where to_char(a.opTime,'yyyy') = :opTime group by a.opOs ";
		QueryLog os_qc = new QueryLog(os_sql);
		os_qc.setParameter("opTime", lastyear);

		List<Object[]> os_rlst = os_qc.list();
		JSONObject os_json = new JSONObject();
		if (os_rlst != null) {
			for (Object[] objs : os_rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					os_json.put(type, value);
				}

			}
		}
		SLogClientinfo os_clientinfo = new SLogClientinfo();
		os_clientinfo.setCountType("3");// 统计全部系统
		os_clientinfo.setLogType("4");// 按年统计
		os_clientinfo.setCountKey(lastyear);
		os_clientinfo.setContent(os_json.toString());
		os_clientinfo.setCreateTime(createTime);

		try {
			tx = qc.getTransaction();
			tx.save(clientinfo);
			tx.save(os_clientinfo);
			tx.commit();
			// result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS,
			// Messages.getString("systemMsg.success"));
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			// result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR,
			// Messages.getString("systemMsg.exception"));
			if (tx != null)
				tx.rollback();
			return Action.ERROR;
		}
	}

	@SuppressWarnings("unchecked")
	private String statisticsYearOfLongin() {
		// 获取昨日时间
		TransactionCache tx = null;
		Calendar cal = Calendar.getInstance();
		Date createTime = cal.getTime();
		cal.add(Calendar.DATE, -1);
		String lastyear = new SimpleDateFormat("yyyy").format(cal.getTime());

		// 查询统计浏览器信息
		String sql = "select a.opExplorer , count(a.opExplorer) from SLog a where to_char(a.opTime,'yyyy') = :opTime and a.funcId = 'acl_user/login' group by a.opExplorer ";
		QueryLog qc = new QueryLog(sql);
		qc.setParameter("opTime", lastyear);

		List<Object[]> rlst = qc.list();
		JSONObject json = new JSONObject();
		if (rlst != null) {
			for (Object[] objs : rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					json.put(type, value);
				}
			}
		}
		SLogClientinfo clientinfo = new SLogClientinfo();
		clientinfo.setCountType("2");// 统计登录浏览器
		clientinfo.setLogType("4");// 按日统计
		clientinfo.setCountKey(lastyear);
		clientinfo.setContent(json.toString());
		clientinfo.setCreateTime(createTime);

		// 查询统计系统信息
		String os_sql = "select a.opOs , count(a.opOs) from SLog a where to_char(a.opTime,'yyyy-MM-dd') = :opTime and a.funcId = 'acl_user/login' group by a.opOs ";
		QueryLog os_qc = new QueryLog(os_sql);
		os_qc.setParameter("opTime", lastyear);

		List<Object[]> os_rlst = os_qc.list();
		JSONObject os_json = new JSONObject();
		if (os_rlst != null) {
			for (Object[] objs : os_rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					os_json.put(type, value);
				}

			}
		}
		SLogClientinfo os_clientinfo = new SLogClientinfo();
		os_clientinfo.setCountType("4");// 统计登录操作系统
		os_clientinfo.setLogType("4");// 按日统计
		os_clientinfo.setCountKey(lastyear);
		os_clientinfo.setContent(os_json.toString());
		os_clientinfo.setCreateTime(createTime);

		try {
			tx = qc.getTransaction();
			tx.save(clientinfo);
			tx.save(os_clientinfo);
			tx.commit();
			// result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS,
			// Messages.getString("systemMsg.success"));
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			// result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR,
			// Messages.getString("systemMsg.exception"));
			if (tx != null)
				tx.rollback();
			return Action.ERROR;
		}

	}

	@SuppressWarnings("unchecked")
	private String statisticsQuater() {
		// 获取上个季度
		TransactionCache tx = null;
		Calendar cal = Calendar.getInstance();
		Date createTime = cal.getTime();
		String lastMonth = new SimpleDateFormat("yyyy-MM").format(cal.getTime());

		// 上个季度
		String quater = changeMonth2Quater(lastMonth);

		String lastquater = changeQuater2LastQuater(quater);

		// 查询统计浏览器信息
		String sql = "select a.opExplorer , count(a.opExplorer) from SLog a where to_char(a.opTime,'yyyy-Q') = :opTime group by a.opExplorer ";
		QueryLog qc = new QueryLog(sql);
		qc.setParameter("opTime", lastquater);

		List<Object[]> rlst = qc.list();
		JSONObject json = new JSONObject();
		if (rlst != null) {
			for (Object[] objs : rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					json.put(type, value);
				}
			}
		}
		SLogClientinfo clientinfo = new SLogClientinfo();
		clientinfo.setCountType("1");// 统计全部浏览器
		clientinfo.setLogType("3");// 按季度统计
		clientinfo.setCountKey(lastquater);
		clientinfo.setContent(json.toString());
		clientinfo.setCreateTime(createTime);

		// 查询统计系统信息
		String os_sql = "select a.opOs , count(a.opOs) from SLog a where to_char(a.opTime,'yyyy-Q') = :opTime group by a.opOs ";
		QueryLog os_qc = new QueryLog(os_sql);
		os_qc.setParameter("opTime", lastquater);

		List<Object[]> os_rlst = os_qc.list();
		JSONObject os_json = new JSONObject();
		if (os_rlst != null) {
			for (Object[] objs : os_rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					os_json.put(type, value);
				}

			}
		}
		SLogClientinfo os_clientinfo = new SLogClientinfo();
		os_clientinfo.setCountType("3");// 统计全部系统
		os_clientinfo.setLogType("3");// 按季度统计
		os_clientinfo.setCountKey(lastquater);
		os_clientinfo.setContent(os_json.toString());
		os_clientinfo.setCreateTime(createTime);

		try {
			tx = qc.getTransaction();
			tx.save(clientinfo);
			tx.save(os_clientinfo);
			tx.commit();
			// result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS,
			// Messages.getString("systemMsg.success"));
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			// result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR,
			// Messages.getString("systemMsg.exception"));
			if (tx != null)
				tx.rollback();
			return Action.ERROR;
		}
	}

	@SuppressWarnings("unchecked")
	private String statisticsQuaterOfLogin() {
		// 获取昨日时间
		TransactionCache tx = null;
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, -1);
		String lastMonth = new SimpleDateFormat("yyyy-MM").format(cal.getTime());

		String quater = changeMonth2Quater(lastMonth);

		String lastquater = changeQuater2LastQuater(quater);

		// 查询统计浏览器信息
		String sql = "select a.opExplorer , count(a.opExplorer) from SLog a where to_char(a.opTime,'yyyy-Q') = :opTime and a.funcId = 'acl_user/login' group by a.opExplorer ";
		QueryLog qc = new QueryLog(sql);
		qc.setParameter("opTime", lastquater);

		List<Object[]> rlst = qc.list();
		JSONObject json = new JSONObject();
		if (rlst != null) {
			for (Object[] objs : rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					json.put(type, value);
				}
			}
		}
		SLogClientinfo clientinfo = new SLogClientinfo();
		clientinfo.setCountType("2");// 统计登录浏览器
		clientinfo.setLogType("3");// 按日统计
		clientinfo.setCountKey(lastquater);
		clientinfo.setContent(json.toString());
		clientinfo.setCreateTime(cal.getTime());

		// 查询统计系统信息
		String os_sql = "select a.opOs , count(a.opOs) from SLog a where to_char(a.opTime,'yyyy-Q') = :opTime and a.funcId = 'acl_user/login' group by a.opOs ";
		QueryLog os_qc = new QueryLog(os_sql);
		os_qc.setParameter("opTime", lastquater);

		List<Object[]> os_rlst = os_qc.list();
		JSONObject os_json = new JSONObject();
		if (os_rlst != null) {
			for (Object[] objs : os_rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					os_json.put(type, value);
				}

			}
		}
		SLogClientinfo os_clientinfo = new SLogClientinfo();
		os_clientinfo.setCountType("4");// 统计登录操作系统
		os_clientinfo.setLogType("3");// 按日统计
		os_clientinfo.setCountKey(lastquater);
		os_clientinfo.setContent(os_json.toString());
		os_clientinfo.setCreateTime(cal.getTime());

		try {
			tx = qc.getTransaction();
			tx.save(clientinfo);
			tx.save(os_clientinfo);
			tx.commit();
			// result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS,
			// Messages.getString("systemMsg.success"));
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			// result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR,
			// Messages.getString("systemMsg.exception"));
			if (tx != null)
				tx.rollback();
			return Action.ERROR;
		}
	}

	@SuppressWarnings("unchecked")
	private String statisticsMonth() {
		// 获取上个月的月份
		TransactionCache tx = null;
		Calendar cal = Calendar.getInstance();
		Date createTime = cal.getTime();
		cal.add(Calendar.MONTH, -1);
		String lastMonth = new SimpleDateFormat("yyyy-MM").format(cal.getTime());

		// 查询统计浏览器信息
		String sql = "select a.opExplorer , count(a.opExplorer) from SLog a where to_char(a.opTime,'yyyy-MM') = :opTime group by a.opExplorer ";
		QueryLog qc = new QueryLog(sql);
		qc.setParameter("opTime", lastMonth);

		List<Object[]> rlst = qc.list();
		JSONObject json = new JSONObject();
		if (rlst != null) {
			for (Object[] objs : rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					json.put(type, value);
				}
			}
		}
		SLogClientinfo clientinfo = new SLogClientinfo();
		clientinfo.setCountType("1");// 统计全部浏览器
		clientinfo.setLogType("2");// 按月统计
		clientinfo.setCountKey(lastMonth);
		clientinfo.setContent(json.toString());
		clientinfo.setCreateTime(createTime);

		// 查询统计系统信息
		String os_sql = "select a.opOs , count(a.opOs) from SLog a where to_char(a.opTime,'yyyy-MM') = :opTime group by a.opOs ";
		QueryLog os_qc = new QueryLog(os_sql);
		os_qc.setParameter("opTime", lastMonth);

		List<Object[]> os_rlst = os_qc.list();
		JSONObject os_json = new JSONObject();
		if (os_rlst != null) {
			for (Object[] objs : rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					json.put(type, value);
				}
			}
		}
		SLogClientinfo os_clientinfo = new SLogClientinfo();
		os_clientinfo.setCountType("3");// 统计全部系统
		os_clientinfo.setLogType("2");// 按月统计
		os_clientinfo.setCountKey(lastMonth);
		os_clientinfo.setContent(os_json.toString());
		os_clientinfo.setCreateTime(createTime);

		try {
			tx = qc.getTransaction();
			tx.save(clientinfo);
			tx.save(os_clientinfo);
			tx.commit();
			// result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS,
			// Messages.getString("systemMsg.success"));
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			// result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR,
			// Messages.getString("systemMsg.exception"));
			if (tx != null)
				tx.rollback();
			return Action.ERROR;
		}
	}

	@SuppressWarnings("unchecked")
	private String statisticsMonthOfLogin() {
		// 获取昨日时间
		TransactionCache tx = null;
		Calendar cal = Calendar.getInstance();
		Date createTime = cal.getTime();
		cal.add(Calendar.MONTH, -1);
		String lastMonth = new SimpleDateFormat("yyyy-MM").format(cal.getTime());

		// 查询统计浏览器信息
		String sql = "select a.opExplorer , count(a.opExplorer) from SLog a where to_char(a.opTime,'yyyy-MM') = :opTime and a.funcId = 'acl_user/login' group by a.opExplorer ";
		QueryLog qc = new QueryLog(sql);
		qc.setParameter("opTime", lastMonth);

		List<Object[]> rlst = qc.list();
		JSONObject json = new JSONObject();
		if (rlst != null) {
			for (Object[] objs : rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					json.put(type, value);
				}
			}
		}
		SLogClientinfo clientinfo = new SLogClientinfo();
		clientinfo.setCountType("2");// 统计登录浏览器
		clientinfo.setLogType("2");// 按日统计
		clientinfo.setCountKey(lastMonth);
		clientinfo.setContent(json.toString());
		clientinfo.setCreateTime(createTime);

		// 查询统计系统信息
		String os_sql = "select a.opOs , count(a.opOs) from SLog a where to_char(a.opTime,'yyyy-MM') = :opTime and a.funcId = 'acl_user/login' group by a.opOs ";
		QueryLog os_qc = new QueryLog(os_sql);
		os_qc.setParameter("opTime", lastMonth);

		List<Object[]> os_rlst = os_qc.list();
		JSONObject os_json = new JSONObject();
		if (os_rlst != null) {
			for (Object[] objs : os_rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					os_json.put(type, value);
				}

			}
		}
		SLogClientinfo os_clientinfo = new SLogClientinfo();
		os_clientinfo.setCountType("4");// 统计登录操作系统
		os_clientinfo.setLogType("2");// 按日统计
		os_clientinfo.setCountKey(lastMonth);
		os_clientinfo.setContent(os_json.toString());
		os_clientinfo.setCreateTime(createTime);

		try {
			tx = qc.getTransaction();
			tx.save(clientinfo);
			tx.save(os_clientinfo);
			tx.commit();
			// result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS,
			// Messages.getString("systemMsg.success"));
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			// result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR,
			// Messages.getString("systemMsg.exception"));
			if (tx != null)
				tx.rollback();
			return Action.ERROR;
		}

	}

	@SuppressWarnings("unchecked")
	private String statisticsDay() {
		// 获取昨日时间
		TransactionCache tx = null;
		Calendar cal = Calendar.getInstance();
		Date createTime = cal.getTime();
		cal.add(Calendar.DATE, -1);
		String yesterday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
		// 查询统计浏览器信息
		String sql = "select a.opExplorer , count(a.opExplorer) from SLog a where to_char(a.opTime,'yyyy-MM-dd') = :opTime group by a.opExplorer ";
		QueryLog qc = new QueryLog(sql);
		qc.setParameter("opTime", yesterday);

		List<Object[]> rlst = qc.list();
		JSONObject json = new JSONObject();
		if (rlst != null) {
			for (Object[] objs : rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					json.put(type, value);
				}
			}
		}
		SLogClientinfo clientinfo = new SLogClientinfo();
		clientinfo.setCountType("1");// 统计全部浏览器
		clientinfo.setLogType("1");// 按日统计
		clientinfo.setCountKey(yesterday);
		clientinfo.setContent(json.toString());
		clientinfo.setCreateTime(createTime);

		// 查询统计操作系统信息
		String os_sql = "select a.opOs , count(a.opOs) from SLog a where to_char(a.opTime,'yyyy-MM-dd') = :opTime group by a.opOs ";
		QueryLog os_qc = new QueryLog(os_sql);
		os_qc.setParameter("opTime", yesterday);

		List<Object[]> os_rlst = os_qc.list();
		JSONObject os_json = new JSONObject();
		if (os_rlst != null) {
			for (Object[] objs : os_rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					os_json.put(type, value);
				}

			}
		}
		SLogClientinfo os_clientinfo = new SLogClientinfo();
		os_clientinfo.setCountType("3");// 统计全部系统
		os_clientinfo.setLogType("1");// 按日统计
		os_clientinfo.setCountKey(yesterday);
		os_clientinfo.setContent(os_json.toString());
		os_clientinfo.setCreateTime(createTime);

		try {
			tx = qc.getTransaction();
			tx.save(clientinfo);
			tx.save(os_clientinfo);
			tx.commit();
			// result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS,
			// Messages.getString("systemMsg.success"));
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			// result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR,
			// Messages.getString("systemMsg.exception"));
			if (tx != null)
				tx.rollback();
			return Action.ERROR;
		}

	}

	@SuppressWarnings("unchecked")
	private String statisticsDayOfLogin() {
		// 获取昨日时间
		TransactionCache tx = null;
		Calendar cal = Calendar.getInstance();
		Date createTime = cal.getTime();
		cal.add(Calendar.DATE, -1);
		String yesterday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
		// 查询统计浏览器信息
		String sql = "select a.opExplorer , count(a.opExplorer) from SLog a where to_char(a.opTime,'yyyy-MM-dd') = :opTime and a.funcId = 'acl_user/login' group by a.opExplorer ";
		QueryLog qc = new QueryLog(sql);
		qc.setParameter("opTime", yesterday);

		List<Object[]> rlst = qc.list();
		JSONObject json = new JSONObject();
		if (rlst != null) {
			for (Object[] objs : rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					json.put(type, value);
				}
			}
		}
		SLogClientinfo clientinfo = new SLogClientinfo();
		clientinfo.setCountType("2");// 统计登录浏览器
		clientinfo.setLogType("1");// 按日统计
		clientinfo.setCountKey(yesterday);
		clientinfo.setContent(json.toString());
		clientinfo.setCreateTime(createTime);

		// 查询统计系统信息
		String os_sql = "select a.opOs , count(a.opOs) from SLog a where to_char(a.opTime,'yyyy-MM-dd') = :opTime and a.funcId = 'acl_user/login' group by a.opOs ";
		QueryLog os_qc = new QueryLog(os_sql);
		os_qc.setParameter("opTime", yesterday);

		List<Object[]> os_rlst = os_qc.list();
		JSONObject os_json = new JSONObject();
		if (os_rlst != null) {
			for (Object[] objs : os_rlst) {
				if (objs[0] == null) {
					continue;
				} else {
					String type = objs[0].toString();
					String value = objs[1].toString();
					os_json.put(type, value);
				}

			}
		}
		SLogClientinfo os_clientinfo = new SLogClientinfo();
		os_clientinfo.setCountType("4");// 统计登录操作系统
		os_clientinfo.setLogType("1");// 按日统计
		os_clientinfo.setCountKey(yesterday);
		os_clientinfo.setContent(os_json.toString());
		os_clientinfo.setCreateTime(createTime);

		try {
			tx = qc.getTransaction();
			tx.save(clientinfo);
			tx.save(os_clientinfo);
			tx.commit();
			// result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS,
			// Messages.getString("systemMsg.success"));
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			// result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR,
			// Messages.getString("systemMsg.exception"));
			if (tx != null)
				tx.rollback();
			return Action.ERROR;
		}

	}

	private String changeMonth2Quater(String lastMonth) {
		String[] getMonth = lastMonth.split("-");
		String year = getMonth[0];
		int month = Integer.parseInt(getMonth[1]);
		String lastquater = null;
		switch (month) {
		case 1:
		case 2:
		case 3:
			lastquater = year + "-" + 1;
			break;
		case 4:
		case 5:
		case 6:
			lastquater = year + "-" + 2;
			break;
		case 7:
		case 8:
		case 9:
			lastquater = year + "-" + 3;
			break;
		case 10:
		case 11:
		case 12:
			lastquater = year + "-" + 4;
			break;
		}

		return lastquater;
	}

	private String changeQuater2LastQuater(String quater) {
		String[] date = quater.split("-");
		int currentQuater = Integer.parseInt(date[1]) - 1;
		int year = Integer.parseInt(date[0]);
		if (currentQuater <= 0) {
			currentQuater = 4;
			year = year - 1;
		}

		String lastQuater = year + "-" + currentQuater;
		return lastQuater;
	}
}
